$(document).on('pageinit', function(){

    $('#registration_form').validate({
        rules: {
            email: {
                required: true,
                maxlength: 50
            },
            password: {
                required: true,
                minlength: 4
            },
            password_repeat:{
                required: true,
                equalTo: "#input_password"
            },
            first_name:{
                required: true,
                maxlength: 35
            },
            last_name:{
                required: true,
                maxlength: 35
            }
        },
        messages: {
            email: {
                required: "Email is required.",
                maxlength: "Can't be longer then 50 characters."
            },
            password: {
                required: "Password is required.",
                minlength: "Your password has to be at least 4 characters."
            },
            password_repeat:{
                required: "Please repeat your password.",
                equalTo: "The passwords have to match!"
            },
            first_name:{
                required: "First name is required.",
                maxlength: "Can't be longer then 35 characters."
            },
            last_name:{
                required: "Last name is required.",
                maxlength: "Can't be longer then 35 characters."
            }
        },
        errorPlacement: function (error, element) {
            if (element.is("input") && !element.is('input[type="hidden"]'))
                error.insertAfter(element.parent());
            else
                error.insertAfter(element);
        }
    });

});